/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.apestar.modules.report.paymentbenefitlog.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.apestar.common.config.Global;
import cn.apestar.common.persistence.Page;
import cn.apestar.common.web.BaseController;
import cn.apestar.modules.report.paymentbenefitlog.entity.PaymentBenefitLog;
import cn.apestar.modules.report.paymentbenefitlog.service.PaymentBenefitLogService;

/**
 * 金额日志查询Controller
 * @author yudw
 * @version 2016-09-07
 */
@Controller
@RequestMapping(value = "${adminPath}/paymentbenefitlog/paymentBenefitLog")
public class PaymentBenefitLogController extends BaseController {

    @Autowired
    private PaymentBenefitLogService paymentBenefitLogService;

    @ModelAttribute
    public PaymentBenefitLog get(@RequestParam(required = false) String id) {
        PaymentBenefitLog entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = paymentBenefitLogService.get(id);
        }
        if (entity == null) {
            entity = new PaymentBenefitLog();
        }
        return entity;
    }

    @RequestMapping(value = {"list" , ""})
    public String list(PaymentBenefitLog paymentBenefitLog, HttpServletRequest request, HttpServletResponse response, Model model) {
        if (!StringUtils.isEmpty(paymentBenefitLog.getUserName())) {
            Page<PaymentBenefitLog> page = paymentBenefitLogService.findPage(new Page<PaymentBenefitLog>(request, response), paymentBenefitLog);
            model.addAttribute("page", page);
        }
        return "modules/report/paymentbenefitlog/paymentBenefitLogList";
    }

    @RequestMapping(value = "form")
    public String form(PaymentBenefitLog paymentBenefitLog, Model model) {
        model.addAttribute("paymentBenefitLog", paymentBenefitLog);
        return "modules/paymentbenefitlog/paymentBenefitLogForm";
    }

    @RequestMapping(value = "save")
    public String save(PaymentBenefitLog paymentBenefitLog, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, paymentBenefitLog)) {
            return form(paymentBenefitLog, model);
        }
        paymentBenefitLogService.save(paymentBenefitLog);
        addMessage(redirectAttributes, "保存金额日志查询成功");
        return "redirect:" + Global.getAdminPath() + "/paymentbenefitlog/paymentBenefitLog/?repage";
    }

    @RequestMapping(value = "delete")
    public String delete(PaymentBenefitLog paymentBenefitLog, RedirectAttributes redirectAttributes) {
        paymentBenefitLogService.delete(paymentBenefitLog);
        addMessage(redirectAttributes, "删除金额日志查询成功");
        return "redirect:" + Global.getAdminPath() + "/paymentbenefitlog/paymentBenefitLog/?repage";
    }

}